// API配置
const BASE_URL = 'https://your-api-domain.com'

// 请求封装
const request = (url, options = {}) => {
  return new Promise((resolve, reject) => {
    uni.request({
      url: BASE_URL + url,
      method: options.method || 'GET',
      data: options.data || {},
      header: {
        'Content-Type': 'application/json',
        ...options.header
      },
      success: (res) => {
        if (res.statusCode === 200) {
          resolve(res.data)
        } else {
          reject(res)
        }
      },
      fail: (err) => {
        reject(err)
      }
    })
  })
}

// 设备统计
export const countDeviceNum = (data) => {
  return request('/api/device/count', {
    method: 'POST',
    data
  })
}

// 用户统计
export const countUserNum = (data) => {
  return request('/api/user/count', {
    method: 'POST',
    data
  })
}

// 设备提醒列表
export const leftBottom = (data) => {
  return request('/api/device/warnings', {
    method: 'POST',
    data
  })
}

// 设备分布地图
export const centerMap = (data) => {
  return request('/api/map/distribution', {
    method: 'POST',
    data
  })
}

// 安装计划
export const installationPlan = (data) => {
  return request('/api/installation/plan', {
    method: 'POST',
    data
  })
}

// 报警次数
export const alarmNum = (data) => {
  return request('/api/alarm/count', {
    method: 'POST',
    data
  })
}

// 报警排名
export const ranking = (data) => {
  return request('/api/alarm/ranking', {
    method: 'POST',
    data
  })
}

// 数据统计
export const rightBottom = (data) => {
  return request('/api/alarm/statistics', {
    method: 'POST',
    data
  })
}

export default {
  countDeviceNum,
  countUserNum,
  leftBottom,
  centerMap,
  installationPlan,
  alarmNum,
  ranking,
  rightBottom
}

